package fr.miage.ageco.dataaccess.mappers;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import fr.miage.ageco.dataaccess.bo.Competence;

public interface CompetenceMapper {

	@Select("SELECT * FROM Competence")
	List<Competence> getAllCompetences();

	@Select("SELECT * FROM Competence WHERE  id = #{id}")
	Competence getCompetence(@Param("id") Integer id);
	
	@Select("SELECT c.* FROM competence c,posseder p WHERE c.id=p.idCompetence AND idEmploye = #{id}")
	List<Competence> getCompetenceForEmploye(@Param("id") Integer id);

	@Insert("INSERT INTO Competence (id, nom) VALUES (#{id},#{nom})")
	public int insertCompetence(Competence competence);
	
	@Insert("INSERT INTO posseder (id, nom) VALUES (#{idCompetence},#{idEmploye})")
	public int insertCompetenceForEmploye(@Param("idCompetence") Integer idCompetence,@Param("idEmploye") Integer idEmploye);

	@Update("UPDATE Competence SET nom = #{nom} WHERE id = #{id}")
	public int updateCompetence(Competence competence);
	
	@Delete("DELETE FROM Competence WHERE id = #{id}")
	public int deleteCompetence(Competence competence);
	
	@Delete("DELETE FROM posseder WHERE idCompetence = #{idCompetence} AND  idEmploye = #{idEmploye}" )
	public int deleteCompetenceForEmploye(@Param("idCompetence") Integer idCompetence,@Param("idEmploye") Integer idEmploye);
	
}
